using System;
using System.Collections.Generic;
using UniversalAdmin.Domain.Entities;

namespace UniversalAdmin.Domain.Entities.App;

public class User : EntityBase
{
    public string Username { get; set; } = string.Empty;
    public string Password { get; set; } = string.Empty;
    public string Email { get; set; } = string.Empty;
    public string? Phone { get; set; }
    public string? Avatar { get; set; }

    // 领域事件集合
    public List<object> DomainEvents { get; } = new List<object>();

    // 添加用户新增领域事件
    public void AddUserCreatedEvent()
    {
        DomainEvents.Add(new UserCreatedEvent(this));
    }

    // 添加用户修改领域事件
    public void AddUserUpdatedEvent()
    {
        DomainEvents.Add(new UserUpdatedEvent(this));
    }

    // 添加用户删除领域事件
    public void AddUserDeletedEvent()
    {
        DomainEvents.Add(new UserDeletedEvent(this));
    }

    // Navigation properties
    public virtual ICollection<Role> Roles { get; set; } = new List<Role>();
    public virtual ICollection<OperationLog> OperationLogs { get; set; } = new List<OperationLog>();
    public virtual ICollection<File> Files { get; set; } = new List<File>();
    public virtual ICollection<Article> Articles { get; set; } = new List<Article>();
    public void AssigRole(Role role)
    {
        if (!Roles.Contains(role))
        {
            Roles.Add(role);
        }
    }
    public void RemoveRole(Role role)
    {
        if (Roles.Contains(role))
            Roles.Remove(role);
    }
}

public class UserCreatedEvent : MediatR.INotification
{
    public User User { get; }
    public UserCreatedEvent(User user)
    {
        User = user;
    }
}

public class UserUpdatedEvent : MediatR.INotification
{
    public User User { get; }
    public UserUpdatedEvent(User user)
    {
        User = user;
    }
}

public class UserQueriedEvent : MediatR.INotification
{
    public User User { get; }
    public UserQueriedEvent(User user)
    {
        User = user;
    }
}

public class UserDeletedEvent : MediatR.INotification
{
    public User User { get; }
    public UserDeletedEvent(User user)
    {
        User = user;
    }
}
